﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices; 


namespace ArithmeticExpressionCalculator
{
    class Program
    {
        [DllImport("kernel32.dll")]
        public static extern int QueryPerformanceFrequency
        (
            ref Int64 lpFrequency
        );

        [DllImport("kernel32.dll")]
        public static extern int QueryPerformanceCounter
        (
            ref Int64 lpPerformanceCount
        );
        static void Main(string[] args)
        {
            CalculatorFacade calculator = new CalculatorFacade();
            Console.WriteLine("Вычисляем красивые арифметические выражения\n \t\tДля выхода введите 0\n");
            while (true)
            {
                Console.WriteLine("Введите пожалуйста выражение:\n");
                string str = Console.ReadLine();
                if (str == "0") break;
                double result = 0;
                try
                {
                    System.Int64 freq = 0;
                    QueryPerformanceFrequency(ref freq);

                    System.Int64 time1 = 0;
                    QueryPerformanceCounter(ref time1);

                    result = calculator.Execute(str);

                    System.Int64 time2 = 0;
                    QueryPerformanceCounter(ref time2);
                    time2 -= time1;

                    double span = (double)time2 / freq;

                    Console.WriteLine("Время выполнения: \n" + span);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    continue;
                }
                Console.WriteLine("Ответ:" + result);
            }
         }
    }
}
